<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>物品置换</title>
	<%@ include file="/view/common/tags.jsp"%>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"> </script>
</head>
<body>
	<section class="content">
    	<div class="row">
            <div class="col-md-12">
                <div class="box">
                	<div class="box-body">
						<div class="panel panel-default">
                            <div class="panel-body" style="padding-bottom:5px;">
                                <form class="form-horizontal" action="" method="post" id="dataForm">
                                    <input type="hidden" id="token" name="token" value=""/>
                                	<div class="searchMenu">
                                	    <div>
                                            <label>装备类型：</label>
                                            <sk:select cssClass="form-control select" id="parentId" name="wm[EQUIP_PARENT_ID]" value="${page.wm.ROW_ID}" requiredInit="true" ajaxURL="${userInfoV1}/gameGoodsType/typeSelect?wm[TYPE_FLAG]=11" onchange="TagUtil.fillOptions('parentId');">
                                                <option value="">请选择</option>
                                            </sk:select>
                                        </div>
                                        <div>
                                            <label>装备分类：</label>
                                            <sk:select cssClass="form-control select" id="equipTypeId" name="wm[EQUIP_TYPE_ID]" value="${page.wm.EQUIP_TYPE_ID}" ajaxURL="${userInfoV1}/gameGoodsType/smallTypeSelect?wm[OPEN_FLAG]=1" parentCascadedSelect="parentId" parentParamName="parentId" >
                                                <option value="">请选择</option>
                                            </sk:select>
                                        </div>
                                        </div>

                                        <div class="mal10" >
                                            <button type="button"  class="btn btn-primary btn-sm"  onclick="findData()"><span class='glyphicon glyphicon-search'></span>查&nbsp;询</button>
                                            <sk:button type="button"  rightKey="20170816153425"  _class="btn btn-success btn-sm"  onclick="add()"><span class='glyphicon glyphicon-plus'></span>添&nbsp;加</sk:button>
                                        </div>
                                	</div>
                                </form>
                        	</div>
						</div>
                        <table class="table table-hover table-condensed table-bordered table-striped" id="dataTable" >
                            <thead>
                            	<tr>
                                	<th data-field="index" data-align="center" data-sortable="false" data-formatter="indexFormatter" >序号</th>
                                    <th data-field="gameName" data-align="center" data-sortable="true">游戏</th>
                                	<th data-field="equipType" data-align="center" data-sortable="true">装备分类</th>
                                	<th data-field="affixType" data-align="center" data-formatter="affixTypeFormatter" data-sortable="true">词缀类型</th>
                                	<th data-field="affixProperty" data-align="center" data-sortable="true">词缀属性</th>
                                    <th data-field="affixTier" data-align="center" data-sortable="true">Tier</th>
                                    <th data-field="affixContent" data-align="center" data-sortable="true">词缀内容</th>
                                    <th data-field="affixLevel" data-align="center" data-sortable="true">等级</th>
                                    <th data-field="affixPropertyScope" data-align="center" data-sortable="true">词缀属性范围</th>
                                    <th data-field="prob" data-align="center" data-sortable="true">几率</th>
                                    <th data-field="price" data-align="center" data-sortable="true">价格</th>
                                    <th data-field="openFlag" data-align="center" data-formatter="openFlagFormatter" data-sortable="true">是否开启</th>
                                    <th data-field="optAccount" data-align="center" data-sortable="true">操作人</th>
                                    <th data-field="optTime" data-align="center" data-sortable="true" data-formatter="timeFormatter_point" >操作时间</th>
                                    <th data-field="deleteButton" data-align="center" data-sortable="false" data-formatter="buttonFormatter">操作</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
       	</div>
	</section>
   <%@ include file="/view/common/footer.jsp"%>
</body>
<script>
	// 提示信息
	var msgg='<%=request.getAttribute("msg")%>';
	if (msgg && msgg!=null && msgg!='null') { 
		  layer.msg(msgg);
	}
	var tableIndex = 0; // 添加修改的弹出框的ID
	
	// 加载table 数据
    $(function(){
    	$("#token").val(sessionStorage.getItem("token"));
    	
        $("#dataTable").bootstrapTable({ 
            url: "${userInfoV1}/gameEquipAffix/data.json",
            method:"get", 
            contentType: "application/x-www-form-urlencoded",
            pagination:true,
            sidePagination:"server",
            queryParams: function(params) {
            	//alert(JSON.stringify(params));
                return $.extend({}, params, parseJson(decodeURIComponent($("#dataForm").serialize())));     
            }
        });
    })
	
	// 启用/停用 字段格式化
    function openFlagFormatter(value, row) {
        var html = "";
        if (row.openFlag == '1') {
            html = "<span class='text-success'>启用 </span>&nbsp;&nbsp;&nbsp;&nbsp;"
            html += "<button id='btn_edit' type='button' onclick='_stop("+row.rowId+", "+row.openFlag+", \""+row.gameName+ "\");'    class='btn btn-default btn-sm '><span class='glyphicon glyphicon-stop'></span>停用</button>";
        } else {
            html = "<span class='text-warning'>停用 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
            html += "<button id='btn_edit' type='button' onclick='_stop("+row.rowId+", "+row.openFlag+", \""+row.gameName+ "\");'    class='btn btn-default btn-sm '><span class='glyphicon glyphicon-ok'></span>启用</button>";
        }
        return html;
    }
    
    function affixTypeFormatter(value, row) {
        var html = "";
        if (row.affixType == '0') {
            html = "前缀"
        } else {
            html = "后缀"
        }
        return html;
    }
    
    
	// 操作 字段格式化
    function buttonFormatter(value, row, index) {
        /* if (row.delFlag == 0) {
            var caozuo3 = "<button id='btn_edit' type='button' onclick='deleteEmp("+row.rowId+","+row.openFlag+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-remove'></span>&nbsp;删&nbsp;除&nbsp;</button>";
        } */
        var caozuo = "<button id='btn_edit' type='button' onclick='_update("+row.rowId+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>修 改</button>";
        caozuo += "<button id='btn_edit' type='button' onclick='deleteEmp("+row.rowId+","+row.openFlag+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-remove'></span>&nbsp;删&nbsp;除&nbsp;</button>";
        return caozuo;
    }
        
    // 查询
    function findData(){
       $("#dataTable").bootstrapTable("refresh",{} ); 
    } 

    // 行点击事件
    $(function(){
         $("body").on("click","table>tbody>tr",function(){
          $(this).css("background","#e1ecf1").siblings().css("background","");
       });
    })
    
    // 弹出添加的窗口
    function add(){
    	tableIndex = layer.open({
            type: 2,
            title: "添加",
            closeBtn: 1,
            shadeClose: true,
            area: ['700px', '600px'],
            content: "${sysManagerV1}/gameEquipAffix/toAddEquipAffix?rowId=0&flag=0",
            btn: ["确 认","关 闭"], 
            yes: function(index, layero){
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                iframeWin.add();
            }
        });
    }
    
    // 弹出添加的窗口      修改功能
    function _update(rowId){
    	tableIndex = layer.open({
            type: 2,
            title: "修改",
            closeBtn: 1,
            shadeClose: true,
            area: ['700px', '600px'],
            content: "${sysManagerV1}/gameEquipAffix/toAddEquipAffix?rowId=" + rowId + "&flag=1",
            btn: ["确 认","关 闭"], 
            yes: function(index, layero){
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                iframeWin.add();
            }
        });
    }

    //  启用/停用
    function _stop(rowId, openFlag, gameName){
        var descStr = '【启用】<a style="color:red"></a>';
        if (openFlag == 1) {
            descStr = '【停用】<a style="color:red"></a>';
        }
        openFlag = Math.abs(Number(openFlag) - 1);
        layer.confirm('您确认'+descStr+'吗？', {btn: ['确认', '取消']},
        function(){
            if (rowId == null || rowId == "") {
                layer.msg("id不能为空!");
                return;
            }
            $.ajax({
                url: "${userInfoV1}/gameEquipAffix/updateUseState",
                type: "post",
                cache: false,
                data: {rowId:rowId, openFlag:openFlag, token: sessionStorage.getItem("token")},
                dataType:"json",
                async:false,
                success: function(data) {
                    if (data == 1) { 
                        layer.msg(descStr+"成功", {icon: 1});
                        findData();
                    } else if(data == "index"){
                        window.location.href="${sysManagerV1}/";
                    } else {
                        layer.msg(descStr+"失败", {icon: 5});
                    }
                }
            });
        });
    }
    
    //删除
    function deleteEmp(rowId, openFlag){
        var descStr = "【删除】";
        layer.confirm('您确认'+descStr+'?', {
            btn: ['确认', '取消']  
        },
        function(){
            var url = "${userInfoV1}/gameEquipAffix/deleteGameEquipAffix?rowId="+rowId+"&openFlag="+openFlag+"&token="+sessionStorage.getItem("token");
            $.ajax({
                url: "${userInfoV1}/gameEquipAffix/deleteGameEquipAffix",
                type: "post",
                cache: false,
                data: {rowId:rowId, openFlag:openFlag, token: sessionStorage.getItem("token")},
                dataType:"json",
                async:false,
                success: function(data) {
                	if (data == 1) { 
                        layer.msg(descStr+"成功", {icon: 1});
                        findData();
                    } else if (data == 3) {
                        layer.msg(descStr+"失败,该游戏启用中");
                    } else if(data == "index"){
                        window.location.href="${sysManagerV1}/";
                    } else {
                        layer.msg(descStr+"失败", {icon: 5});
                    }
                }
            });
        });
    }
  
</script>
</html>